/***
 * Automatically toggle a DIV next to the link.
 * @param {Object} link The triggered link element
 * @return Null
 */
function toggleThis(link)
{
    var content = link.nextSibling;
    while(content)
	{
        if(content.className && content.className.indexOf('toggle-content')!==-1)
		{
            var status = content.style.display;
            content.style.display = status=='block' ? 'none':'block';
        }
        content = content.nextSibling;
    }
    return ;
}

/***
 * This function manually deal with anchors clicking due to the scrolling
 * problem in parent window.
 * Function will be called by onclick event.
 * @return Always return false to avoid native anchor event triggered
 */
function avoidScroll()
{
    var h = this.getAttribute('href');
    var i = h.indexOf('#') + 1;
    var id = h.substr(i);
    var tar = document.getElementById(id);
    if(tar){
        window.scroll(0, tar.offsetTop);
    }
    return false;
}


function onToggleThis()
{
	toggleThis(this);
	return false;
}

window.onload = function()
{
    var toggle_links = document.getElementsByTagName('a');
    var i = toggle_links.length;
    while(i--)
	  {
        var t = toggle_links[i];
        if(t.className.indexOf('toggle')!==-1)
		{
            t.onclick = onToggleThis;
        }
		else
		{
            t.onclick = avoidScroll;
        }
    }
};




